// pages/qianshu/qianshu.js

const app = getApp();
var util = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  qr_qs1:function(e){
    wx.showLoading({
      title: '加载中',
      mask:false
    })
    var gz_id = e.currentTarget.dataset.id;
    app.globalData.gz_id1 = gz_id
    var qy_id = e.currentTarget.dataset.idd;
    app.globalData.qy_id1 = qy_id
    var array = [];
    array.push({
      id:gz_id,
      get_value:app.globalData.mr_url1
    },{
      id:qy_id,
      get_value:app.globalData.mr_url
    })
    app.globalData.arry = array
    console.log(JSON.stringify(app.globalData.arry))
    if(app.globalData.mr_url==''){
      setTimeout(function () {
        wx.hideLoading()
      }, 1000)
      wx.showModal({
        title: '温馨提示',
        content: '签名没有，请确认添加',
        success (res) {
          if (res.confirm) {
        
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    }else if(app.globalData.mr_url1==''){
      setTimeout(function () {
        wx.hideLoading()
      }, 1000)
      wx.showModal({
        title: '温馨提示',
        content: '公章没有，请确认添加',
        success (res) {
          if (res.confirm) {
        
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    }else{
      wx.request({
        url: app.globalData.url_l+'api/order/sign_contract',
        method: 'post',
        data: {
          uid:app.globalData.uid,
          ht_id: app.globalData.ht_id,
          array:JSON.stringify(app.globalData.arry)
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: function (res) {
          console.log(res)
           if(res.data.code==1){
            
            wx.showToast({
              title: '签署成功！',
              icon: 'success',
              duration: 2000,
              success:function(){
                setTimeout(function () {
                  //要延时执行的代码
                  setTimeout(function () {
                    wx.hideLoading()
                  }, 1000)
                  wx.navigateBack({
                    data:1,
                    success: function(e) {
                     var page = getCurrentPages().pop();
                     if (page == undefined || page == null) return;
                     page.onLoad();
                 }
                  })
                }, 2000) //延迟时间
      
              }
      
            })
           }else{
             wx.showToast({
                title:res.data.msg,
                icon: 'none',
                duration: 1000,
                success:function(){
                  setTimeout(function () {
                    wx.hideLoading()
                  }, 1000)
                }
              })
           }
        }
      })
    }
  
    // wx.navigateBack();
  },
  qianming:function(e){
    wx.navigateTo({
      url: '../wodeqian_m/wodeqian_m?qian_id='+1,
    })
  },
  gzhang:function(e){
    app.globalData.qy_txid = ""
    wx.navigateTo({
      url: '../qy_gz/qy_gz?qian_id1='+1,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      var that = this;
      var ht_id = options.ht_id;
      app.globalData.ht_id = ht_id;
      
      var TIME = util.formatTime(new Date());
      console.log(TIME)
      this.setData({
        time: TIME,
      });

      wx.request({
        url: app.globalData.url_l+'api/order/ht_qian',
        method: 'post',
        data: {
         id: ht_id,
         uid:app.globalData.uid,
         corpid:app.globalData.corpid
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: function (res) {
          console.log(res)
          console.log(11111111111)
           that.setData({
            qianming:res.data.qianming,
            gongzhang:res.data.gongzhang,
           })
           if(res.data.gongzhang==2){
            that.setData({
              gongzhang_list:res.data.gongzhang_list,
              gongzhang_list1:res.data.gongzhang_list.gz_img,
             })
             app.globalData.mr_url1 = res.data.gongzhang_list.gz_img
           }else if(res.data.gongzhang==1){
            app.globalData.mr_url1 = ""
            that.setData({
              gongzhang_list1:"../../images/qian_s1.png"
            })
           }
           if(res.data.qianming==2){
            that.setData({
              qianming_list:res.data.qianming_list,
              qianming_list1:res.data.qianming_list.qm_img
             })
             app.globalData.mr_url = res.data.qianming_list.qm_img
           }else if(res.data.qianming==1){
            app.globalData.mr_url = ""
            that.setData({
              qianming_list1:"../../images/qian_s2.png"
            })
           }
        }
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
     var that = this;
     if(app.globalData.img_id2==1){
      var array = [];
      array.push({
        id:app.globalData.gz_id1,
        get_value:app.globalData.mr_url1
      },{
        id:app.globalData.qy_id1,
        get_value:app.globalData.mr_url
      })
      app.globalData.arry = array
      console.log(JSON.stringify(app.globalData.arry))
     }else{

     }
     that.setData({
      gongzhang_list1:app.globalData.mr_url1,
      qianming_list1:app.globalData.mr_url
     })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})